/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/


#ifndef STLHELPER_INCLUDED_
#define STLHELPER_INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif


#ifdef max
	#undef max
#endif

#ifdef min
	#undef min
#endif

#pragma warning(disable: 4786)  // identifier was truncated to 'number' characters in the debug information
#include <iostream>

//////////////////////////////////////////////////////////////////////
// STL neccessary declaration for vector
//////////////////////////////////////////////////////////////////////

#pragma warning(push)

#include <yvals.h>              // warning numbers get enabled in yvals.h 

#pragma warning(disable: 4018)  // signed/unsigned mismatch
#pragma warning(disable: 4100)  // unreferenced formal parameter
#pragma warning(disable: 4245)  // conversion from 'type1' to 'type2', signed/unsigned mismatch
#pragma warning(disable: 4663)  // C++ language change: to explicitly specialize class template 'vector'
#pragma warning(disable: 4702)  // unreachable code
#pragma warning(disable: 4710)  // 'function' : function not inlined
#pragma warning(disable: 4786)  // identifier was truncated to 'number' characters in the debug information

#include <vector>
#include <list>
#include <memory> // for auto_ptr
#include <vector>
#include <string>
#include <functional>
#include <fstream>
#include <strstream>
#include <utility>
#include <map>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <new>
#include <limits>

#include <valarray>
#include <algorithm>
#include <boost/test/floating_point_comparison.hpp>

namespace algotools
{
	template <typename T> 
	inline T min(T a, T b)	{ return b < a ? b : a; } 

	template <typename T> 
	inline T max(T a, T b)	{ return  a < b ? b : a; } 

	template <typename T>
	inline bool IsEqual(T x, T y)		
	{ 
    //static boost::test_tools::close_at_tolerance<T> comp( std::numeric_limits<T>::epsilon()/2*10);
      //static boost::test_tools::close_at_tolerance<T> comp( std::numeric_limits<T>::epsilon()/2*10);
      //return comp( x,y);
		return x-y<std::numeric_limits<T>::epsilon()/2*10;
	};
  
	template <typename T>
	inline bool IsGreaterEqual(T x, T y)
	{
		return ( x>=y || IsEqual(x,y) );
	}
	
	template <typename T>
	inline bool IsLowerEqual(T x, T y)
	{
		return ( x<=y || IsEqual(x,y) );
	}
} 



#ifndef _TSTLSTRING
#define _TSTLSTRING
	#include <tchar.h>
	namespace std
	{
		typedef basic_ios<TCHAR>			_tios;
		typedef basic_istream<TCHAR>		_tistream;
		typedef basic_ostream<TCHAR>		_tostream;
		typedef basic_string<TCHAR>			_tstring;
		typedef basic_ifstream<TCHAR>		_tifstream;
		typedef basic_ofstream<TCHAR>		_tofstream;
		typedef basic_istringstream<TCHAR>	_tistringstream;
		typedef basic_ostringstream<TCHAR>	_tostringstream;
	}
#endif


#pragma warning(pop)

//////////////////////////////////////////////////////////////////////
// STL neccessary declaration for assert
//////////////////////////////////////////////////////////////////////

// avoid macro redefinition when using MFC
#ifndef ASSERT

#include <cassert>

// macros for tracking down errors
#ifdef _DEBUG

#define ASSERT( exp )           assert( exp )
#define VERIFY( exp )           assert( exp )
#define TRACE                   ::OutputDebugString

#else

#define ASSERT( exp )           ((void)0)
#define VERIFY( exp )           ((void)(exp))
#define TRACE                   1 ? (void)0 : ::OutputDebugString

#endif  // _DEBUG

#endif  // ASSERT

#endif  // STLHELPER_INCLUDED_
